/*
 * acooly.cn Inc.
 * Copyright (c) 2017 All Rights Reserved.
 * create by ouwen
 * date:2017-09-27
 */
package com.yiji.fintech.musfinance.service.impl;

import com.acooly.core.common.dao.support.PageInfo;
import com.acooly.core.common.service.EntityServiceImpl;
import com.acooly.core.utils.Collections3;
import com.yiji.fintech.musfinance.common.exception.DBException;
import com.yiji.fintech.musfinance.dao.SignContractnoDao;
import com.yiji.fintech.musfinance.entity.SignContractno;
import com.yiji.fintech.musfinance.service.SignContractnoService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 渠道签约合同号 Service实现
 *
 * Date: 2017-09-27 15:29:23
 *
 * @author ouwen
 *
 */
@Service("signContractnoService")
public class SignContractnoServiceImpl extends EntityServiceImpl<SignContractno, SignContractnoDao> implements SignContractnoService {

    @Override
    public List<SignContractno> query(SignContractno signContractno, Map<String, Boolean> sortMap, int pageNum, int pageSize) {
        Map<String,Object> map = new HashMap<>();
        map.put("EQ_signInfoId", signContractno.getSignInfoId());
        map.put("EQ_gatewayChannelApi",signContractno.getGatewayChannelApi());
        PageInfo<SignContractno> pageInfo = new PageInfo<>();
        pageInfo.setCurrentPage(pageNum);
        pageInfo.setCountOfCurrentPage(pageSize);
        try {
            pageInfo = getEntityDao().query(pageInfo, map, sortMap);
        } catch (Exception e) {
            throw new DBException(e.getMessage());
        }
        return pageInfo.getPageResults();
    }

    @Override
    public SignContractno query(SignContractno signContractno) {
        List<SignContractno> signContractnoList =  query(signContractno,null,1,1);
        if(Collections3.isNotEmpty(signContractnoList)){
            return signContractnoList.get(0);
        }
        return null;
    }
}
